package com.hualan.controller;

import com.hualan.pojo.Consultant;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.ConsultantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value="/consultant")
public class ConsultantController {
    @Autowired
    private ConsultantService consultantService;


    @GetMapping(value="/search")
    public Result queryAllConsultant(String name,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pageSize)
    {
        PageResult pageResult  = consultantService.queryAllConsultant(name, page, pageSize);
        return Result.success(pageResult);
    }

    @PostMapping(value="/add")
    public Result addConsultant(@RequestBody Consultant consultant)
    {
        Result result = consultantService.addConsultant(consultant);
        return result;
    }

    @PutMapping(value="/update")
    public Result updateConsultant(@RequestBody Consultant consultant)
    {
        Result result = consultantService.updateConsultant(consultant);
        return result;
    }

    @PutMapping(value="/delete")
    public Result deleteConsultant(@RequestBody List<Integer> ids)
    {
        Result result = consultantService.deleteConsultant(ids);
        return result;
    }

    @GetMapping(value="/searchById")
    public Result searchById(Integer id)
    {
        return Result.success(consultantService.searchById(id));
    }

    @GetMapping("/findConsultant")
    public Result find(@RequestParam("field") String field,@RequestParam("levelName") String levelName){
        List<Consultant> consultants = consultantService.find(field, levelName);
        return Result.success(consultants);
    }



}
